/*
 * Copyright (C) 2004 Bernard Leach, Scott Lawrence, Joshua Oreman, et al.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

/* ********************************************************************** */ 
/* Header Decorations */ 


#ifdef NEVER_EVER
static int hcolor;
/* one for testing... */
void test_draw_decorations( struct header_info * hdr, ttk_surface srf )
{
	ttk_color c = 0;
	char * data;
	if( !hdr ) return;
	data = (char *) hdr->data;

	/* fill the whole back */
	ttk_fillrect( srf,
			0, 0,
			ttk_screen->w, ttk_screen->wy,
			ttk_makecol( 255, 0, 0 ) );

	/* now fill just the center bit */
	if( (hcolor & 7) == 6) hcolor = 0;
	if( (hcolor & 7) == 0) c = ttk_makecol( 255,   0,   0 );
	if( (hcolor & 7) == 1) c = ttk_makecol( 255, 255,   0 );
	if( (hcolor & 7) == 2) c = ttk_makecol(   0, 255,   0 );
	if( (hcolor & 7) == 3) c = ttk_makecol(   0, 255, 255 );
	if( (hcolor & 7) == 4) c = ttk_makecol(   0,   0, 255 );
	if( (hcolor & 7) == 5) c = ttk_makecol( 255,   0, 255 );
	ttk_fillrect( srf,
			hdr->widg->x, 0,
			hdr->widg->x + hdr->widg->w, ttk_screen->wy,
			c );

	/* the left and right sides - find any holes */
	if( hdr->widg->x != 0 )
		ttk_fillrect( srf,
			0, 0,
			hdr->widg->x, ttk_screen->wy,
			ttk_makecol( 0, 255, 0 ) );
	if( hdr->widg->x+hdr->widg->w != ttk_screen->w )
		ttk_fillrect( srf,
			hdr->widg->w + hdr->widg->x, 0,
			ttk_screen->w,  ttk_screen->wy,
			ttk_makecol( 255, 255, 0 ) );
/*
	printf( "Decoration \"%s\"  %d %d\n", data, hdr->widg->x, hdr->widg->w);
*/
}

void test_update_decorations( struct header_info * hdr )
{
/*
	printf( "Update Header Timeout\n" );
*/
	ttk_dirty |= TTK_DIRTY_HEADER;
	hcolor++;
}
#endif


/* this is helpful for getting a real solid color when there's a gradient
   or if there's a regular color */
ttk_color pz_dec_ap_get_solid( char * name )
{
	ttk_color c = ttk_makecol( WHITE );;
	TApItem *ap = ttk_ap_get( name );
	if( ap ) {
		if( ap->type & TTK_AP_COLOR ) {
			c = ap->color;
		} else if( ap->type & TTK_AP_GRADIENT ) {
			c = ap->gradstart;
		}
	} 
	return( c );
}

/* plain - do nothing */
void dec_plain( struct header_info * hdr, ttk_surface srf )
{
	ttk_color c = pz_dec_ap_get_solid( "header.bg" );
	ttk_fillrect( srf, 0, 0, ttk_screen->w, hdr->widg->h, c );
}

/* do it as it's defined in the CS file */
void dec_csdef( struct header_info * hdr, ttk_surface srf )
{
	ttk_ap_fillrect( srf, ttk_ap_get ("header.bg"),
			0, 0, ttk_screen->w, hdr->widg->h ); 
}

/* m-robe style dots */
void dec_dots( struct header_info * hdr, ttk_surface srf )
{
	enum ttk_justification just = pz_get_int_setting( 
					pz_global_config, TITLE_JUSTIFY);
	int tw = ttk_text_width (ttk_menufont, ttk_windows->w->title);
	int pL, pR;
	int xL, xR;
	int sxL, sxR;

	/* starting values */
	xL = hdr->widg->x;
	xR = hdr->widg->x + hdr->widg->w;

	sxL = (ttk_screen->w>>1)+2; /* account for radius */
	sxR = (ttk_screen->w>>1)-2;

	/* account for text */
	if( just == TTK_TEXT_LEFT )
		xL += (tw + 6);
	else if( just == TTK_TEXT_RIGHT )
		xR -= (tw + 6);
	else {
		sxL -= ((tw>>1) + 6);
		sxR += ((tw>>1) + 6);
	}

	/* draw the dots, from the center out */
	for( pL = (ttk_screen->w)>>1, pR = (ttk_screen->w)>>1;
	     pL > 1;
	     pL -= 11, pR += 11 ){

		if( pL>xL && pL <= sxL ) {
			ttk_draw_icon( pz_icon_dot, srf, 
				pL - 3, (ttk_screen->wy >> 1) - 2, 
				ttk_ap_getx( "header.accent" ),
				ttk_ap_getx( "header.accent" )->color );
		}
		if( pR<xR && pR >= sxR ) {
			ttk_draw_icon( pz_icon_dot, srf, 
				pR - 3, (ttk_screen->wy >> 1) - 2, 
				ttk_ap_getx( "header.accent" ),
				ttk_ap_getx( "header.accent" )->color );
		}
	}
}


/* dots over the background solid color */
void dec_plaindots( struct header_info * hdr, ttk_surface srf )
{
	dec_plain( hdr, srf );
	dec_dots( hdr, srf );
}


#define RAISED  (0)
#define LOWERED (1)
void dec_draw_3d( ttk_surface srf, int x1, int y1, int x2, int y2, int updown )
{
	ttk_color nw, se;

	if( updown == LOWERED ) {
		se = pz_dec_ap_get_solid( "header.shine" );
		nw = pz_dec_ap_get_solid( "header.shadow" );
	} else {
		nw = pz_dec_ap_get_solid( "header.shine" );
		se = pz_dec_ap_get_solid( "header.shadow" );
	}

	ttk_line( srf, x2, y1, x2, y2, se );
	ttk_line( srf, x1, y2, x2, y2, se );

	ttk_line( srf, x1, y1, x2, y1, nw );
	ttk_line( srf, x1, y1, x1, y2, nw );
}


/* Amiga Decorations */
void dec_draw_AmigaXX( struct header_info * hdr, ttk_surface srf, int WhichAmigaDOS )
{
	int tw = ttk_text_width (ttk_menufont, ttk_windows->w->title);
	enum ttk_justification just = pz_get_int_setting( 
					pz_global_config, TITLE_JUSTIFY);
	int i;
	int xp1 = hdr->widg->x + 2;
	int xp2 = hdr->widg->x + hdr->widg->w -1;
	int tx1 = 0, tx2 = 0;
	double yo, xo;
	int hw = hdr->widg->h>>1;

	dec_plain( hdr, srf );

	/* draw the backing */
	if( WhichAmigaDOS == 40 || WhichAmigaDOS == 41 ) {
		int r1, g1, b1, r2, g2, b2;
		ttk_color halfway;
		ttk_unmakecol_ex( pz_dec_ap_get_solid( "header.shine" ),
					&r1, &g1, &b1, srf);
		ttk_unmakecol_ex( pz_dec_ap_get_solid( "header.shadow" ),
					&r2, &g2, &b2, srf);
		halfway = ttk_makecol( (r1+r2)>>1, (g1+g2)>>1, (b1+b2)>>1 );

		/* 3d box */
		dec_draw_3d( srf, 0, 0, 
			ttk_screen->w-1, hdr->widg->h-1, RAISED );
		/* gradient */
		ttk_vgradient( srf, 1, 2, 
			    ttk_screen->w-1, hdr->widg->h-2,
			    ttk_ap_getx( "header.shadow" )->color,
			    ttk_ap_getx( "header.shine" )->color );
		/* transitional */
		ttk_line( srf, 1, 1, ttk_screen->w-2, 1, halfway );
		ttk_line( srf, 1, hdr->widg->h-2, 
				ttk_screen->w-2, hdr->widg->h-2, halfway );
	}

	/* draw the faux close box, if applicable. */
	if( hdr->widg->x == 0 && WhichAmigaDOS != 41 ) {
		xp1 = hdr->widg->h-1;	/* square gadget */
		xo = ((float)hdr->widg->h) / 8.0;
		yo = ((float)hdr->widg->h) / 8.0;

		if( WhichAmigaDOS < 20 ) {
			ttk_fillrect( srf,  
					(int) (xo*1),  (int) (yo*1),
					(int) (xo*7),  (int) (yo*7),
					pz_dec_ap_get_solid ("header.fg"));
			ttk_fillrect( srf, 
					(int) (xo*1.6), (int) (yo*1.6),
					(int) (xo*6.4), (int) (yo*6.4),
					pz_dec_ap_get_solid ("header.bg"));
			ttk_fillrect (srf, 
					(int) (xo*3.1), (int) (yo*3.1),
					(int) (xo*4.8), (int) (yo*4.8),
					pz_dec_ap_get_solid ("header.accent"));
		} else if( WhichAmigaDOS < 40 ) {
			dec_draw_3d( srf, 0, 0, hdr->widg->h-2, 
				hdr->widg->h-1, RAISED );
			ttk_fillrect( srf, hw-1, xo*2+2, hw+2, xo*6-1,
				pz_dec_ap_get_solid( "header.shine" ));
			ttk_rect( srf, hw-2, xo*2+1, hw+2, xo*6-1,
				pz_dec_ap_get_solid( "header.shadow" ));
		} else { /* 4.0 */
#define AD40CS	(4)
			/* shadow */
			ttk_rect( srf, hw-AD40CS-1, hw-AD40CS, 
				hw+AD40CS, hw+AD40CS,
				pz_dec_ap_get_solid( "header.shadow" ));

			/* shine */
			ttk_rect( srf, hw-AD40CS+1, hw-AD40CS+1,
				hw+AD40CS+1, hw+AD40CS+1,
				pz_dec_ap_get_solid( "header.shine" ));

			/* fill it... */
			ttk_fillrect( srf, hw-AD40CS, hw-AD40CS,
				hw+AD40CS, hw+AD40CS, 
				pz_dec_ap_get_solid( "header.accent" ));

			/* black overlay border */
			ttk_rect( srf, hw-AD40CS, hw-AD40CS,
				hw+AD40CS, hw+AD40CS, ttk_makecol( BLACK ) );
		}

	} else if( WhichAmigaDOS == 20 ) {
		xo = ((float)hdr->widg->h) / 8.0;
		dec_draw_3d( srf, 0, 0, hdr->widg->x - 1, 
				hdr->widg->h-1, RAISED );
	}


	/* draw drag bars */
	if( WhichAmigaDOS == 11 ) {
		/* 1.1 dragbars */
		for (i = 1; i < ttk_screen->wy; i += 2) {
			ttk_line (srf,
				xp1, i, xp2, i,
				ttk_ap_getx ("header.fg") -> color);
		}
	} else if( WhichAmigaDOS == 13 || WhichAmigaDOS == 14 ) {
		/* 1.3 dragbars */
		int o = ttk_screen->wy / 4;
		ttk_fillrect( srf, 
			xp1 + o,  o,
			xp2 - o,  o*2 - 1,
			pz_dec_ap_get_solid( "header.fg" ));
		ttk_fillrect( srf,
			xp1 + o,  hdr->widg->h - o*2 + 1,
			xp2 - o,  hdr->widg->h - o,
			pz_dec_ap_get_solid( "header.fg" ));
	} else if( WhichAmigaDOS == 20 ) {
		dec_draw_3d( srf, xp1, 0, xp2,
			hdr->widg->h-1, RAISED );
	} 


	if( WhichAmigaDOS == 40 ) {
		/* left separator */
		ttk_ap_vline( srf, ttk_ap_get( "header.shadow" ),
		    xp1, 5, ttk_screen->wy-5 );
		ttk_ap_vline( srf, ttk_ap_get( "header.shine" ),
		    xp1+1, 5, ttk_screen->wy-5 );

		/* right separator */
		ttk_ap_vline( srf, ttk_ap_get( "header.shadow" ),
		    xp2, 5, ttk_screen->wy-5 );
		ttk_ap_vline( srf, ttk_ap_get( "header.shine" ),
		    xp2+1, 5, ttk_screen->wy-5 );

	} else if( WhichAmigaDOS == 20 ) {
		if( hdr->widg->x + hdr->widg->w != ttk_screen->w ) {
		    dec_draw_3d( srf, hdr->widg->x + hdr->widg->w, 0,
				      ttk_screen->w-1, hdr->widg->h-1,
				      RAISED );
		}
	} else if( WhichAmigaDOS != 14 && WhichAmigaDOS != 41 ) {
		/* draw vertical separators - 1.3, 1.1, not 1.4 */
		ttk_fillrect( srf, xp1, 0, xp1+2, hdr->widg->h,
				pz_dec_ap_get_solid( "header.fg" ));
		if( xp2 != ttk_screen->w ) 
			ttk_fillrect( srf, xp2 - 1, 0, xp2 + 1, hdr->widg->h,
				pz_dec_ap_get_solid( "header.fg" ));
	}

	/* blot out the backing for the text */
	pz_header_justification_helper( xp1+3, xp2-3 );

	if( WhichAmigaDOS != 20 ) {
		switch( just ) {
		case( TTK_TEXT_LEFT ):
			tx1 = xp1+1;
			tx2 = xp1+tw+5;
			break;
		case( TTK_TEXT_RIGHT ):
			tx1 = xp2-tw-5;
			tx2 = xp2-1;
			break;
		default: /* center */
			tx1 = (ttk_screen->w - tw - 5) >> 1;
			tx2 = tx1 + tw + 5;
		}
		if( WhichAmigaDOS < 20 ) {
			ttk_fillrect( srf, tx1, 0, tx2, hdr->widg->h,
				pz_dec_ap_get_solid( "header.bg" ));
		}
	}
}

/* thse just call the above appropriately */
void dec_draw_Amiga14( struct header_info * hdr, ttk_surface srf )
{
	dec_draw_AmigaXX( hdr, srf, 14 ); /* AmigaDOS 1.4 (unreleased) */
}

void dec_draw_Amiga13( struct header_info * hdr, ttk_surface srf )
{
	dec_draw_AmigaXX( hdr, srf, 13 ); /* AmigaDOS 1.3 */
}

void dec_draw_Amiga11( struct header_info * hdr, ttk_surface srf )
{
	dec_draw_AmigaXX( hdr, srf, 11 ); /* AmigaDOS 1.1 */
}

void dec_draw_Amiga20( struct header_info * hdr, ttk_surface srf )
{
	dec_draw_AmigaXX( hdr, srf, 20 ); /* AmigaDOS 2.0 */
}

void dec_draw_Amiga40( struct header_info * hdr, ttk_surface srf )
{
	dec_draw_AmigaXX( hdr, srf, 40 ); /* AmigaDOS 4.0 */
}

void dec_draw_Amiga40_plus( struct header_info * hdr, ttk_surface srf )
{
	dec_draw_AmigaXX( hdr, srf, 41 ); /* AmigaDOS 4.0 plus */
}


/* BeOS yellow tab */
void dec_draw_BeOS( struct header_info * hdr, ttk_surface srf )
{
	int tw = ttk_text_width (ttk_menufont, ttk_windows->w->title);
	int www = tw + 10 + hdr->widg->x;

	if( hdr->widg->x == 0 ) {
		www += ttk_screen->wy;	/* add the width of faux close */
	}

	/* always force left justification */
	ttk_header_set_text_justification( TTK_TEXT_LEFT );
	if( hdr->widg->x == 0 ) {
		ttk_header_set_text_position( hdr->widg->x + hdr->widg->h + 4 );
	} else {
		ttk_header_set_text_position( hdr->widg->x + 4 );
	}

	/* backing */
	ttk_fillrect( srf, 0, 0, ttk_screen->w, ttk_screen->wy, 
			ttk_makecol( BLACK ));

	/* yellow tab */
	ttk_fillrect( srf, 0, 0, www, ttk_screen->wy, 
			pz_dec_ap_get_solid( "header.bg" ));

	/* faux close widget */
	/* fill gradient -- unfortunately, we have no diagonal gradient... */
	if( hdr->widg->x == 0 ) {
		ttk_vgradient( srf, 4, 4, 
			    ttk_screen->wy-4, ttk_screen->wy-4,
			    ttk_ap_getx( "header.shine" )->color,
			    ttk_ap_getx( "header.accent" )->color );
		       
		/* draw these to get the NE/SW corners */
		ttk_ap_hline( srf, ttk_ap_get( "header.shadow" ), 
		    4, ttk_screen->wy-4, 4 );
		ttk_ap_vline( srf, ttk_ap_get( "header.shadow" ),
		    4, 4, ttk_screen->wy-4 );

		/* and the main container boxes... */
		ttk_rect( srf, 4, 4, 
			    ttk_screen->wy-4, ttk_screen->wy-4,
			    ttk_ap_getx( "header.shadow" )->color );
		ttk_rect( srf, 5, 5, 
			    ttk_screen->wy-3, ttk_screen->wy-3,
			    ttk_ap_getx( "header.shine" )->color );
	}
	
	/* 3d effect */
	/* top */
	ttk_line( srf, 0, 0, www, 0,
			ttk_ap_getx( "header.shine" )->color );
	/* left */      
	ttk_line( srf, 0, 0, 0, ttk_screen->wy,
			ttk_ap_getx( "header.shine" )->color );
	/* bottom - handled by header.line */
	/* right */
	ttk_line( srf, www-1, 1,
			www-1, ttk_screen->wy,
			ttk_ap_getx( "header.shadow" )->color ); 
}

/* Atari ST's horrible looking TOS interface */

/* TOS hashmarks
**   x x . . x x . . 
**   x x . . x x . . 
*/
static unsigned char dec_tos_hash[] = { 4, 1,
	3, 3, 0, 0, 3, 3, 0, 0,
	3, 3, 0, 0, 3, 3, 0, 0
};
void dec_draw_STTOS( struct header_info * hdr, ttk_surface srf )
{
	int x,y, xp;
	int startx = hdr->widg->x;
	ttk_color bg_c = pz_dec_ap_get_solid( "header.bg" );
	ttk_color fg_c = pz_dec_ap_get_solid( "header.fg" );
	int tw = ttk_text_width (ttk_menufont, ttk_windows->w->title);
	enum ttk_justification just = 
		(int) pz_get_int_setting (pz_global_config, TITLE_JUSTIFY);

	dec_plain( hdr, srf );

	if( startx == 0 ) {
		startx += hdr->widg->h;
	}

	/* draw the horrid looking texture */
	for( x=startx+2 ; x<hdr->widg->x+hdr->widg->w ; x += 4 ) {
		for( y=0 ; y<hdr->widg->h ; y ++ ) {
			if( (y&0x02) == 0 ) {
				ttk_draw_icon( dec_tos_hash, srf, x, y, 
				    ttk_ap_getx( "header.fg" ), fg_c );
			}
		}
	}

	/* i don't know what's worse... that people thinks this looks good
	   or that i'm wasting so much time to make it available for them  */

	/* draw the crummy close box */
	if( hdr->widg->x == 0 ) {
		int v = hdr->widg->h-1;
		int offs = v>>3;

		ttk_fillrect( srf, 0, 0, v, v, bg_c );
		ttk_fillrect( srf, offs, offs,
			( (offs&1)?1:0 ) + v-offs,
			( (offs&1)?1:0 ) + v-offs,
			fg_c );

		/* TL-BR */
		ttk_line( srf,  0, 0,  v,   v,  bg_c );
		ttk_line( srf,  0, 1,  v-1, v,  bg_c );
		ttk_line( srf,  1, 0,  v, v-1,  bg_c );

		/* BL-TR */
		ttk_line( srf,  0, v,    v, 0,   bg_c );
		ttk_line( srf,  0, v-1,  v-1, 0, bg_c );
		ttk_line( srf,  1, v,    v, 1,   bg_c );
	}

	/* tweak the text for the closebox */
	pz_header_justification_helper( startx + 6, 
					hdr->widg->x + hdr->widg->w - 4 );
	switch( just ) {
	case( TTK_TEXT_LEFT ):
		xp = startx + 2;
		break;
	case( TTK_TEXT_RIGHT ):
		xp = hdr->widg->x + hdr->widg->w - tw - 6;
		break;
	default:
		xp = ((ttk_screen->w - tw ) >> 1) -3;
		break;
	}
	/* backwash..er.. backfill */
	ttk_fillrect( srf, xp, 0, xp+tw+6, hdr->widg->h, bg_c );

	/* draw the separators */
	ttk_fillrect( srf, startx, 0, startx+2, hdr->widg->h-1, fg_c );
	ttk_fillrect( srf, hdr->widg->x+hdr->widg->w-1, 0, 
			   hdr->widg->x+hdr->widg->w+1, hdr->widg->h-1, fg_c );
	
}

/* Apple Lisa */
void dec_draw_Lisa( struct header_info * hdr, ttk_surface srf )
{
	int tw = ttk_text_width (ttk_menufont, ttk_windows->w->title);
	ttk_color c;
	int xw = tw + 8 + 3;
	int xp;
	int xL, xR;
	int v = ttk_screen->wy -1;

	dec_plain( hdr, srf );

	ttk_header_set_text_justification( TTK_TEXT_CENTER );
	xp = ((ttk_screen->w - tw)>>1) - 5;
	ttk_header_set_text_position( ttk_screen->w >>1 );

	/* center */
	c = ttk_ap_getx( "header.accent" )->color;
	ttk_fillrect( srf, xp, 0, xp+xw, v+1, c);

	xL = xp;  xR = xp + xw;

	/* four-bars */
	ttk_fillrect( srf, xL-5, 0, xL-1, v+1, c );
	ttk_fillrect( srf, xR+1, 0, xR+5, v+1, c );

	/* three-bars */
	ttk_fillrect( srf, xL-9, 0, xL-6, v+1, c );
	ttk_fillrect( srf, xR+6, 0, xR+9, v+1, c );

	/* two-bars */
	ttk_fillrect( srf, xL-12, 0, xL-10, v+1, c );
	ttk_fillrect( srf, xR+10, 0, xR+12, v+1, c );

	/* lines */
	ttk_line( srf, xL-14, 0, xL-14, v, c );
	ttk_line( srf, xL-16, 0, xL-16, v, c );
	ttk_line( srf, xL-18, 0, xL-18, v, c );

	ttk_line( srf, xR+13, 0, xR+13, v, c );
	ttk_line( srf, xR+15, 0, xR+15, v, c );
	ttk_line( srf, xR+17, 0, xR+17, v, c );
}

/* Apple Macintosh System 7 */
void dec_draw_MacOS7( struct header_info * hdr, ttk_surface srf )
{
	int yb, xp;
	int r,g,b;
	ttk_color c;
	int tw = ttk_text_width (ttk_menufont, ttk_windows->w->title);
	int xw = tw + 8;

	dec_plain( hdr, srf );

	ttk_header_set_text_justification( TTK_TEXT_CENTER );
	xp = ((ttk_screen->w - tw)>>1) - 4;
	ttk_header_set_text_position( ttk_screen->w >>1 );

	ttk_unmakecol_ex( pz_dec_ap_get_solid( "header.accent" ),
					&r, &g, &b, srf);
	
	for( yb = 5 ; yb < hdr->widg->h-3 ; yb += 2 ) {
		ttk_ap_hline( srf, ttk_ap_getx( "header.shadow" ),
				1, ttk_screen->w-2, yb );
	}

	/* draw a lighter box around it, accent color */
	c = ttk_makecol( (r+255)>>1, (g+255)>>1, (b+255)>>1 );
	ttk_fillrect( srf, xp, 0, xp+xw, hdr->widg->h,
			pz_dec_ap_get_solid( "header.bg" ));
	ttk_rect( srf, 0, 0, ttk_screen->w, hdr->widg->h, c );

	/* draw the closebox */
	if( hdr->widg->x == 0 ) {
		ttk_fillrect( srf, 6, 2,
			hdr->widg->h-1, hdr->widg->h-2,
			pz_dec_ap_get_solid( "header.bg" ) );

		/* draw these to get the NE/SW corners */
		ttk_ap_hline( srf, ttk_ap_get( "header.accent" ),
			7, hdr->widg->h-3, 5 );
		ttk_ap_vline( srf, ttk_ap_get( "header.accent" ),
			7, 5, hdr->widg->h-5 );

		/* and the main container boxes... */
		ttk_rect( srf, 7, 5, 
			hdr->widg->h-3, hdr->widg->h-5,
			pz_dec_ap_get_solid( "header.accent" ) );
		ttk_rect( srf, 8, 6,
			hdr->widg->h-2, hdr->widg->h-4, c );
	}

}

/* Apple Macintosh MacOS 8 */
void dec_draw_MacOS8( struct header_info * hdr, ttk_surface srf )
{
	int yb, v, v2;
	int tw = ttk_text_width( ttk_menufont, ttk_windows->w->title );
	int xp = ((ttk_screen->w - tw)>>1) - 4;
	ttk_header_set_text_justification( TTK_TEXT_CENTER );
	ttk_header_set_text_position( ttk_screen->w >>1 );

	dec_plain( hdr, srf );

	/* outer box */
	ttk_rect( srf, 0, 0, ttk_screen->w, ttk_screen->wy,
			pz_dec_ap_get_solid( "header.shine" ));

	v = hdr->widg->h;
	v2 = hdr->widg->x + hdr->widg->w - 5;

	/* dragbar imagery */
	for ( yb=4; yb<ttk_screen->wy-6 ; yb +=2 ) {
		/* left side */
		ttk_ap_hline( srf, ttk_ap_get( "header.shine" ), 
				v, xp-3, yb );
		ttk_ap_hline( srf, ttk_ap_get( "header.shadow" ), 
				v+1, xp-2, yb+1 );

		/* right side */
		ttk_ap_hline( srf, ttk_ap_get( "header.shine" ),
				tw+xp+10, v2, yb );
		ttk_ap_hline( srf, ttk_ap_get( "header.shadow" ),
				tw+xp+11, v2, yb+1 );
	}

	/* draw the closebox */
	if ( hdr->widg->x == 0 ) {
		ttk_vgradient( srf, 4, 4,
				hdr->widg->h-4, hdr->widg->h-4,
				ttk_ap_getx( "header.shadow" )->color,
				ttk_ap_getx( "header.shine" )->color );

		/* outer recess */
		ttk_rect( srf, 4, 4, v-5, v-5, 
				pz_dec_ap_get_solid( "header.shadow" ));
		ttk_rect( srf, 5, 5, v-4, v-4, 
				pz_dec_ap_get_solid( "header.shine" ));
		ttk_rect( srf, 5, 5, v-5, v-5, 
				ttk_makecol( BLACK ));

		/* inner button */
		ttk_rect( srf, 6, 6, v-6, v-6, 
				pz_dec_ap_get_solid( "header.shine" ));
		ttk_line( srf, 7, v-7, v-7, v-7, 
				pz_dec_ap_get_solid( "header.shadow" ));
		ttk_line( srf, v-7, 7, v-7, v-7, 
				pz_dec_ap_get_solid( "header.shadow" ));
	}


}

